package org.example.service.impl;

import org.example.mapper.BrandMapper;
import org.example.pojo.Brand;
import org.example.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceimpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Override
    public List<Brand> queryAllBrand() {
        return brandMapper.queryAllBrand();
    }

    @Override
    public Brand queryBrandById(Integer id) {
        return brandMapper.queryBrandById(id);
    }

    @Override
    public int addBrand(Brand brand) {
        // 设置首字母
        if (brand.getName() != null && !brand.getName().isEmpty()) {
            brand.setFirstChar(brand.getName().substring(0, 1).toUpperCase());
        }
        return brandMapper.addBrand(brand);
    }

    //这是一个更新方法
    @Override
    public int updateBrand(Brand brand) {
        // 设置首字母
        if (brand.getName() != null && !brand.getName().isEmpty()) {
            brand.setFirstChar(brand.getName().substring(0, 1).toUpperCase());
        }
        return brandMapper.updateBrand(brand);
    }

    @Override
    public int deleteBrand(Integer id) {
        return brandMapper.deleteBrand(id);
    }
}
